package com.web.test.config;

import com.web.test.interceptor.CheckUserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

//通过对WebMvcConfigurer配置类的继承来自定义拦截器
//通过InterceptorRegistry帮助配置映射截取程序列表
@Configuration
public class SpringMVCConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> paths=new ArrayList<>();
        paths.add("/css/*");
        paths.add("/images/*");
        paths.add("/js/*");
        paths.add("/login.html");
        paths.add("/register.html");
        paths.add("/doLogin");
        paths.add("/defaultKaptcha");
        paths.add("/doRegister");
        paths.add("/checkUserExist");
        registry.addInterceptor(new CheckUserInterceptor()).addPathPatterns("/**").excludePathPatterns(paths);
    }
}
